Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

128
Visualizações
Getting "document is not defined" in JS

I'm trying to build a simple Blackjack game, and everything was going well, until I started getting the error "document is not defined"... I'm using VS Code with Node, so I just write in the terminal "node index.js" and it always works, however for some reason it's not working now.

Here's the error:

let messageEl = document.getElementById("message-el");
                ^

ReferenceError: document is not defined
    at Object.<anonymous> (C:\Users\draven\Desktop\JAVASCRIPT\Blackjack\index.js:9:17)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

node runs in a server environment, which doesn't have any document or window because it is not a browser environment.

about 4 years ago · Juan Pablo Isaza Relatório

0

document is a web browser concept, it doesn't exist in the node runtime.

Check out this answer for the a great explination: Document in node

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda